﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t211Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t211_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t211Mgr mgr = new t211Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t211(e.Parameters[t211_Filter.ParamPrefix]));
            IList<t211> list = mgr.FindAllByPage_t211(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t211_Filter.ParamPrefix]);
            t211_MainStore.DataSource = list;
            t211_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t211Mgr mgr = new t211Mgr();
            RowSelectionModel sm = t211_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t211 _t211 = new t211();
                _t211.t211_01 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t211(_t211))
                {
                    log.Debug("t211中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t211_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t211Mgr mgr = new t211Mgr();
            t211 _t211 = new t211();
            if (Hid.Text.Length > 0)
                _t211 = mgr.FindById_t211(int.Parse(Hid.Text));
            
			_t211.t211_02 = Txtt211_02.Text.Trim();
			_t211.t211_03 = Txtt211_03.Text.Trim();
			_t211.t211_04 = Txtt211_04.Text.Trim();
			_t211.t211_05 = Txtt211_05.Text.Trim();
			_t211.t211_06 = Txtt211_06.Text.Trim();
			_t211.t211_07 = Txtt211_07.Text.Trim();
			_t211.t211_08 = Txtt211_08.Text.Trim();
			_t211.t211_09 = Txtt211_09.Text.Trim();
			_t211.t211_10 = Txtt211_10.Text.Trim();
			_t211.t211_11 = Txtt211_11.Text.Trim();
			_t211.t211_12 = Txtt211_12.Text.Trim();
			_t211.t211_13 = Txtt211_13.Text.Trim();
			_t211.t211_14 = Txtt211_14.Text.Trim();
			_t211.t211_15 = Txtt211_15.Text.Trim();
			_t211.t211_16 = Txtt211_16.Text.Trim();
			_t211.t211_17 = Txtt211_17.Text.Trim();
			_t211.t211_18 = Txtt211_18.Text.Trim();
			_t211.t211_19 = Txtt211_19.Text.Trim();
			_t211.t211_20 = Txtt211_20.Text.Trim();
			_t211.t211_21 = Txtt211_21.Text.Trim();
			_t211.t211_22 = Txtt211_22.Text.Trim();
			_t211.t211_23 = Txtt211_23.Text.Trim();
			_t211.t211_24 = Txtt211_24.Text.Trim();
			_t211.t211_25 = Txtt211_25.Text.Trim();
			_t211.t211_26 = Txtt211_26.Text.Trim();
			_t211.t211_27 = Txtt211_27.Text.Trim();
			_t211.t211_28 = Txtt211_28.Text.Trim();
			_t211.t211_29 = Txtt211_29.Text.Trim();
			_t211.t211_30 = Txtt211_30.Text.Trim();
			_t211.t211_31 = Txtt211_31.Text.Trim();
			_t211.t211_32 = Txtt211_32.Text.Trim();
			_t211.t211_33 = Txtt211_33.Text.Trim();
			_t211.t211_34 = Txtt211_34.Text.Trim();
			_t211.t211_35 = Txtt211_35.Text.Trim();
			_t211.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t211(_t211);
            else
                isok = mgr.Add_t211(_t211);
            if (isok)
            {
                t211_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t211中执行了保存（插入或修改），并成功");
                t211_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}